#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>


void my_cat (int fd, int step)
{
    char            *buff;
    int             ctl;

    buff = malloc (step);

    while ( (ctl = read (fd , buff , step )) )
    {
        if (ctl == -1)
        {
            if (errno == EINTR)
                continue;
            perror ("mycat , read error ");
            exit (-1);
        }
            
        write ( STDOUT_FILENO, buff, ctl);
    }
}

int main (int argc, char **argv)
{
    int             fd;
    int             stp;
    if (argc < 3)
    {
        write (STDERR_FILENO, "missing an arg\n",16 );
        return -1;
    }

    if ( 0 > (fd = open (argv[1], O_RDONLY)) )
    {
        perror ("open");
        return -1;
    }
    stp = atoi (argv[2]);

    my_cat (fd, stp);
    while (-1 == close(fd));

    return 0;

}
